﻿using Microsoft.AspNetCore.Mvc;
using System.Text.Json.Nodes;

namespace TestServer.Controllers
{
    //[Route("[controller]/[action]")]
    public class ApiController : ControllerBase
    {
        public IActionResult Get()
        {
            var name = Request.Query["name"];
            string token = Request.Headers["token"];
            string? c = Request.Cookies["c"];
            return Content($"返回文本abc==>{name},token==>{token},cookie==>{c}");
        }

        public IActionResult GetJson()
        {
            return Ok(new { id = 12, AGE = 29, Name = "你好aa" });
        }

        public IActionResult GetFile()
        {
            return File("1你.jpg", "application/octet-stream", "a1你好1a.jpg");
        }

        public async Task<IActionResult> Post()
        {
            var form = await Request.ReadFormAsync();
            string name = form["name"];
            return Content("这是post" + name);
        }

        public IActionResult PostBody([FromBody] JsonObject obj)
        {
            return Ok(obj);
        }

        public async Task<IActionResult> PostFile()
        {
            var form = await Request.ReadFormAsync();
            var file = form.Files;
            return Content(file.Count.ToString());
        }
    }

}
